<div th:fragment="user-nav">


    <div class="user-login" id="notLogin">
        <a th:href="@{/cmsEnglish/userCenter.html}" id="txtUserName" class="inputsub-zc"></a>
        <!--          <a href="https://www.qingqingblog.com/e/member/cp/" target="_parent">会员中心</a>-->
        <a href="javascript:void(0)" onclick="logout()" class="inputsub-dl">退出</a>

    </div>
    <div class="user-login" style="display:none" id="login">
        <!--          <div class="header-hello">您好，<span class="header-username">游客</span><span class="header-groupname"></span>-->
        <!--        <input type="submit" name="Submit" value="登录" class="inputsub-dl">-->
        <a href="javascript:void(0)" onclick="openLogin()" class="inputsub-dl">登录</a>
        <a href="javascript:void(0)" onclick="openRegister()" class="inputsub-zc">注册</a>
        <th:block th:include="include-login :: login" />
        <th:block th:include="include-register :: register" />
        <!--      <div class="searchico"></div>-->
    </div>
    <script>
        $(document).ready(function () {
            var deviceId = new Date().getTime();
            //用户信息
            getUserInfo(deviceId);

        });

        function getUserInfo() {
            $.get("/user/c/getLoginUserInfo", function (res, status) {
                if (res.success) {
                    $("#notLogin").show();
                    $("#login").hide();
                    $("#txtUserName").text(res.data.userName + " 您好");
                } else {
                    $("#notLogin").hide();
                    $("#login").show();
                }
            });
        }


        function logout(){
            if (!confirm('确认要退出?')) {
                return;
            }

            $.ajax({type:"POST",url:"/user/c/logout",dataType:'JSON', contentType:'application/json', data:{},success:function(result){
                    if(result.success){
                        //设置cookie
                        // var token = result.data.token;
                        // alert("登录成功");
                        window.location = "/cmsEnglish/index.html";
                    }else{
                        alert(result.message || '退出失败');
                    }

                }});
        }

        // Window.alert = function(msg){
        //     $.message({type:'success',content:msg});
        // }
    </script>


</div>
